package com.yxq.mdt.app.modules.auction.ui;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.wuhenzhizao.titlebar.widget.CommonTitleBar;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.modules.auction.adapter.AuctionProfitListAdapter;
import com.yxq.mdt.app.modules.auction.bean.AuctionList;
import com.yxq.mdt.app.modules.auction.bean.AuctionProfitBean;
import com.yxq.mdt.app.modules.auction.bean.AuctionTxBean;
import com.yxq.mdt.app.modules.auction.model.AuctionModel;
import com.yxq.mdt.app.modules.auction.presenter.AuctionContract;
import com.yxq.mdt.app.modules.auction.presenter.AuctionPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 提现记录
 */
public class AuctionProfitListAc extends BaseActivity<AuctionPresenter> implements AuctionContract.View {
    @BindView(R.id.titlebar)
    CommonTitleBar titlebar;
    @BindView(R.id.auction_withdrawal_list_money)
    TextView auctionWithdrawalListMoney;
    @BindView(R.id.auction_list_recyclerView)
    RecyclerView auctionListRecyclerView;
    AuctionProfitListAdapter auctionProfitListAdapter;
    List<AuctionProfitBean.PmUserCashDrillPageListBean.ListBean> auctionProfitBeans;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;

    @Override
    public int getLayoutId() {
        return R.layout.activity_auction_profit;
    }

    @Override
    public void initView() {
        mPresenter = new AuctionPresenter(this, new AuctionModel());
        auctionProfitBeans = new ArrayList<>();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mActivity);
        auctionListRecyclerView.setLayoutManager(linearLayoutManager);
        auctionProfitListAdapter = new AuctionProfitListAdapter(R.layout.item_auction_cash, auctionProfitBeans);
        auctionListRecyclerView.setAdapter(auctionProfitListAdapter);
        refreshLayout.setOnRefreshListener(refreshLayout -> {
            page = 1;
            mPresenter.getUserCashList(page + "", "30");
        });
        refreshLayout.setOnLoadMoreListener(refreshLayout -> {
            page++;
            mPresenter.getUserCashList(page + "", "30");
        });
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        refreshLayout.autoRefresh();
    }


    @Override
    public void onLoadAuctionListByTypeSuccess(AuctionList auctionList) {

    }

    @Override
    public void onLoadAuctionListByTypeFailed() {

    }

    @Override
    public void onLoadUserCashListSuccess(AuctionProfitBean auctionProfitBean) {
        refreshLayout.finishRefresh();
        refreshLayout.finishLoadMore();
        if (auctionProfitBean.getCount() != null) {
            auctionWithdrawalListMoney.setText("￥" + auctionProfitBean.getCount());
        } else {
            auctionWithdrawalListMoney.setText("0");
        }

        if (auctionProfitBean.getPmUserCashDrillPageList() != null && auctionProfitBean.getPmUserCashDrillPageList().getList().size() > 0) {
            if (page == 1) {
                auctionProfitListAdapter.setNewData(auctionProfitBean.getPmUserCashDrillPageList().getList());
            } else {
                auctionProfitListAdapter.addData(auctionProfitBean.getPmUserCashDrillPageList().getList());
            }
        } else {
            refreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    @Override
    public void onLoadUserCashListFailed() {

    }

    @Override
    public void onLoadUserIncomeListSuccess(AuctionTxBean auctionTxBean) {

    }

    @Override
    public void onLoadUserIncomeListFailed() {

    }

    @Override
    public void onLoadAddUserCashSuccess(String result) {

    }

    @Override
    public void onLoadAddUserCashFailed(String msg) {

    }
}
